package com.example.poemtest.mine;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.ListView;

import com.example.poemtest.R;
import com.example.poemtest.utils.Constant;
import com.example.poemtest.utils.FullScreenUtil;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 我的提问页面
 */
public class MyQuestionActivity extends AppCompatActivity {

    //属性
    private ImageView back;
    private QuestionListViewAdapter adapter;
    private ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FullScreenUtil.getInstance().fullScreen(this,true);
        setContentView(R.layout.activity_my_question);
        listView = findViewById(R.id.list);
        //点击返回按钮跳转到帮助与反馈页面
        back = findViewById(R.id.back);
        back.setOnClickListener(view->{
            Intent intent = new Intent(this, HelpActivity.class);
            startActivity(intent);
        });
        //防止Constant.questionList里面没有数据，会报空指针
        if (Constant.questionList.size() == 0) {
            Question question = new Question();
            question.setDesc("问题：我的数据里面为什么没有我的体重呢？");
            question.setAnswer("客服：您好！可能因为网络问题等原因，您刷新一" +
                    "下看看！");
            SimpleDateFormat sdf = new SimpleDateFormat();// 格式化时间
            sdf.applyPattern("yyyy-MM-dd");// a为am/pm的标记
            Date date = new Date();// 获取当前时间
            question.setDate(sdf.format(date));
            Constant.questionList.add(question);
        }
        //设置适配器
        adapter = new QuestionListViewAdapter(
                this,
                R.layout.question_item_layout,
                Constant.questionList
        );
        //绑定适配器
        listView.setAdapter(adapter);
    }
}